import {defineStore} from "pinia";

export const useUserStore = defineStore('user', {
    state() {
        return {
            user: null,
            token: null,
        }
    },
    actions: {
        login(user, token) {
            this.user = user;
            this.token = token;
        },
        logout() {
            this.user = null;
            this.token = null;
        },
        removeToken() {
            this.token = null;
        }
    },
    getters: {
        isLoggedIn: (state) => !!state.token,
    },
    persist: {
        enabled: true,
        strategies: [
            {
                key: 'user',
                storage: localStorage,
                paths: ["user", "token"],
            }
        ]
    }
})